#include<iostream>
#include<algorithm>
const int N = 1e6 + 10;
int sum[N], n, x;
using namespace std;
int main()
{
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		cin >> x;
		sum[i] = sum[i - 1] + x;
	}
	int ret = -1e10;
	int premin = 0;
	for (int i = 1; i <= n; i++)
	{
		ret = max(ret, sum[i] - premin);
		premin = min(premin, sum[i]);
	}
	cout << ret << endl;
	return 0;
}
//#include<iostream>
//#include<algorithm>
//const int N = 1e6 + 10;
//int sum[N], n,x;
//using namespace std;
//int main()
//{
//	cin >> n;
//	for (int i = 1; i <= n; i++)
//	{
//		cin >> x;
//		sum[i] = sum[i - 1] + x;
//	}
//	int ret = -1e10 - 10;
//	int premin = 0;
//	for (int i = 1; i <= n; i++)
//	{
//		ret = max(ret,sum[i] - premin);
//		premin = min(premin, sum[i]);
//	}
//	cout << ret << endl;
//	return 0;
//}